﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>下一步接受人员列表</title>
    <!--
    1, 退回界面。
    2，需要 FK_Flow, FK_Node,WorkID, FID.
    3, 调用方法 ReturnWork.htm?FK_Flow=001&FK_Node=103&WorkID=232&FID=23
    -->
    
    <link href="../Scripts/bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/components-rounded.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/font-awesome.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/themes/default/style.min.css" rel="stylesheet" />
    <link href="../Scripts/easyUI145/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/easyUI145/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../Scripts/layui/layui/css/modules/layer/default/layer.css" rel="stylesheet" />
    <script src="../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/QueryString.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.cokie.min.js"></script>
    <script type="text/javascript" src="../Scripts/QueryString.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <script src="../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <script src="../Scripts/layui/layui/lay/modules/layer.js"></script>
    <script src="../../DataUser/JSLibData/CommonShowConfig.js"></script>
    <script src="../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../Scripts/QueryString.js" type="text/javascript"></script>
    <script type="text/javascript" src="../Scripts/DealErrInfo.js"></script>

    <link href="../../DataUser/Style/ccbpm.css" rel="Stylesheet" />
    <!-- 导入配置文件. -->
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script src="../Comm/Gener.js" type="text/javascript"></script>

    <style type="text/css">
        body {
            background: transparent;
        }

            body div {
                text-align: left;
            }

        #Message {
            width: 100%;
        }

        #viewModal {
            max-width: 1000px;
        }

        #SelectEmp {
            position: relative;
            width: 300px;
            border-top: 0;
            display: none;
            margin-top: 5px;
        }

        .addbg {
            background: #CFCFCF;
        }

        #next {
            float: right;
            position: relative;
            width: auto;
            margin-right: 10px;
        }

        button {
            background: #fff;
            color: #000;
            border: 1px solid #ccc !important;
            border-radius: 3px;
            margin: 2px 3px 5px 3px;
            padding: 4px 15px;
        }

            button:hover {
                background: #f5f5f5 !important;
                color: #000;
                border: 1px solid #ccc !important;
            }
    </style>
    <script type="text/javascript">
        var param = {};
        var isSigleSelect = false;
        var selectEmp = "";
        var selectEmpNo = "";
        var IsSend = GetQueryString("IsSend"); //是否发送？该参数是ToNodes.htm 带回来的.
        var isFrameCross = GetQueryString("isFrameCross");
        if (isFrameCross == null || isFrameCross == undefined || isFrameCross == "" || isFrameCross == "null")
            isFrameCross = 0;
        var pageFrom = GetQueryString("PageFrom");
        //判断读秒关闭的参数是否存在
        if ("undefined" == typeof WF_WorkOpt_LeftSecond) {
            var WF_WorkOpt_LeftSecond = 30;
        }
        $(function () {

            if (IsSend == null || IsSend == undefined || IsSend == "")
                IsSend = "1";
            if (IsSend == "0")
                $("#Btn_Send").hide(); //如果是ToNodes.htm调用的就隐藏发送.

            $("#HelpInfo").toggle(); //没有起作用。

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData(); //参数:ToNode,FK_Flow,FK_Node,WorkID
            var data = handler.DoMethodReturnString("AccepterOfGener_Init");
            if (data.indexOf('err@') == 0) {
                alert(data);
                window.parent.close();
                return;
            }
            //获得结果集.该结果集有如下数据: SELECT * FROM WF_SelectAccper
            var sas = JSON.parse(data);

            BindTable(sas);  //开始渲染列表.


            //初始化人员选择窗口
            var selectEmpModalHtml = '<div class="modal fade" id="SelectEmpsModal">' +
                '<div class="modal-dialog" style="width:700px;">'
                + '<div class="modal-content" style="">'
                + '<div class="modal-header">'
                + '<button type="button" class="close" style="color:#000;opacity:1;" data-dismiss="modal" aria-hidden="true">&times;</button>'
                + '<h4 class="modal-title">接受人</h4>'
                + '</div>'
                + '<div class="modal-body" style="border-radius: 0px; ">'
                + '<iframe style="width:100%;border:0px;height:400px;" id="iframeSelectEmpsForm" name="iframeSelectEmpsForm"></iframe>'
                + '</div>'
                + '</div><!-- /.modal-content -->'
                + '</div><!-- /.modal-dialog -->'
                + '</div>';

            $('body').append($(selectEmpModalHtml));

            //获得部门编号.
            var u = new WebUser();
            var dept = u.FK_Dept;

            var IsSelectMore = isSigleSelect == false ? 1 : 0;
            var url = "SelectEmps.htm?FK_Dept=" + dept + "&FK_Node=" + GetQueryString("FK_Node") + "&IsSelectMore=" + IsSelectMore + "&s=" + Math.random();

            //为天业集团做的特殊判断.
            url = url.replace('=101&', '=10102&');

            $('#iframeSelectEmpsForm').attr('src', url);

            $('#Btn_SelectEmps').bind('click', function () {

                $('#SelectEmpsModal').modal().show();

            });
            $(".Msg").hide();

            var int = setInterval("clock()", 1000);

        });

        //是否单项选择.
        var IsSimpleSelector = 0;

        function BindTable(sas) {

            var isDel = true;
            var toNodeID = GetQueryString("ToNode");
            var sa = new Entity("BP.WF.Template.Selector", toNodeID);
            if (sa.IsSimpleSelector == 1) { //是否单项选择.
                isDel = false; //如果是单项选择，就可以有移除按钮.
                isSigleSelect = true;
            }

            IsSimpleSelector = sa.IsSimpleSelector;

            selectEmp = "";
            selectEmpNo = "";
            for (var i = 0; i < sas.length; i++) {
                var sa = sas[i];
                var row = "";
                row += "<tr>";
                row += "<td>" + (i + 1) + "</td>";
                //row += "<td>" + sa.FK_Emp + "</td>";
                row += "<td>" + sa.EmpName + "</td>";
                row += "<td title='" + sa.DeptName + "' >" + sa.DeptName + "</td>";
                row += "<td style='width:40px;'><a href=\"javascript:Up('" + sa.MyPK + "');\" >上移</a></td>";
                row += "<td style='width:40px;'><a href=\"javascript:Down('" + sa.MyPK + "');\" >下移</a></td>";

                if (isDel == true)
                    row += "<td style='width:40px;'><a href=\"javascript:DeleteIt('" + sa.MyPK + "');\" >移除</a></td>";
                else
                    row += "<td style='width:40px;'> <a href=\"javascript:alert('当前节点是单选节点，当前处理人是默认自动计算的处理人，请选择一个处理人，系统就会自动替换掉。');\">帮助</a></td>";

                row += "</tr>";

                $("#Table1 tbody").append(row);
                selectEmp += sa.EmpName + ",";
                selectEmpNo += sa.FK_Emp + ","
            }
        }

        //得到行对象
        function ClearTable() {

            var table = $("#Table1");
            var tbody = $("#Table1 tbody");
            var trArr = $("#Table1 tbody tr");
            for (var i = 0; i < trArr.length; i++) {

                var tr = trArr[i];
                console.info(tr.id);
                if (tr.id == "title")
                    continue;

                tbody.empty();
            }
        }

        function Ref() {
            Reload();
        }

        function Up(mypk) {
            var en = new Entity("BP.WF.Template.SelectAccper", mypk);
            en.DoMethodReturnString("DoUp");
            Reload();
        }
        function Down(mypk) {
            var en = new Entity("BP.WF.Template.SelectAccper", mypk);
            en.DoMethodReturnString("DoDown");
            Reload();
        }
        function DeleteIt(mypk) {
            var en = new Entity("BP.WF.Template.SelectAccper", mypk);
            en.Delete();
            Reload();
            return;
        }

        //确定 执行下一步接受人员列表操作.
        function AddEmps(isSend) {
            var emps = this.document.getElementById("TB_Emps").value;
            if (isSend == false && emps == "") {
                alert('请输入接受人的人员ID,支持拼音查询.');
                return;
            }
            AddEmpsExt(isSend, emps);
        }

        function AddEmpsExt(isSend, emps) {
            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            handler.AddUrlData(); //参数ToNode, WorkID,FK_Node,FK_Flow
            handler.AddPara("AddEmps", emps); //要增加的人员，多个可以用逗号分开.
            var data = handler.DoMethodReturnString("AccepterOfGener_AddEmps");

            if (data.indexOf('err@') == 0) {
                alert(data);
                Reload();
                return;
            }

            if (data.indexOf('info@') == 0) {
                $(".Msg").show();
                $(".Msg").html(data);
                return;
            }
            //是否执行发送?
            if (isSend == true) {
                SendIt();
                return;
            }
            ClearTable();
            var gwls = JSON.parse(data);
            BindTable(gwls);
            document.getElementById("TB_Emps").value = ""; //把人员的文本框清空.
            return;

            $(".foot").hide();
        }

        //执行发送.
        function Send() {

            var emps = this.document.getElementById("TB_Emps").value;
            if (emps != "") {
                this.AddEmps(true); //如果人员不为空，把人员代
                return;
            }

            SendIt();
        }

        function SendIt() {

            var httphandler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
            httphandler.AddUrlData(); //FK_Flow,FK_Node,WorkID,FID,ToNode 等参数.

            $("#Btn_Send").attr("disabled", "disabled"); //把发送按钮设置不可用.
            $("#Btn_Send").text("正在发送请稍候...");
            $("#Btn_Close").attr("disabled", "disabled"); //关闭按钮设置不可以用.
            $("#Btn_SelectEmps").attr("disabled", "disabled"); //选择人按钮不可以用.

            var data = httphandler.DoMethodReturnString("AccepterOfGener_Send");

            if (data.indexOf('err@') == 0) {  //如果发送失败.

                DealErrMsg(data);
                if (msgTech == "") {
                    $(".Msg").show();
                    $(".Msg").html(data);
                    $(".Msg").css("color", "red");
                }

                $("#Btn_Send").attr("disabled", false);
                $("#Btn_Send").text("发送");
                $("#Btn_Close").attr("disabled", false);
                $("#Btn_SelectEmps").attr("disabled", false);
                return;
            }
            if (isFrameCross == 0) {
                if (window.parent != null && window.parent.WindowCloseReloadPage != null && typeof window.parent.WindowCloseReloadPage === "function") {
                    window.parent.WindowCloseReloadPage(data);
                } else {
                    if (typeof WindowCloseReloadPage != 'undefined' && WindowCloseReloadPage instanceof Function)
                        WindowCloseReloadPage(data);
                }
            }

            if (data.indexOf('TurnUrl@') == 0) {  //发送成功时转到指定的URL
                var url = data;
                url = url.replace('TurnUrl@', '');
                parent.window.location.href = url;
                return;
            }

            //发送成功处理.
            $(".Msg").css("color", "");
            data = data.replace("'MyFlowInfo", "'../MyFlowInfo");
            data = data.replace("'MyFlow.htm", "'../MyFlow.htm");
            data = data.replace("'MyFlow.htm", "'../MyFlow.htm");

            data = data.replace("'WFRpt", "'../WFRpt");
            data = data.replace("'WFRpt", "'../WFRpt");

            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");
            data = data.replace("'./Img", "'../Img");

            data = data.replace("'./WorkOpt/", "");
            data = data.replace("'./WorkOpt/", "");
            data = data.replace("'./WorkOpt/", "");
            data = data.replace("'./WorkOpt/", "");

            data = data.replace('<br/>', '');
            data = data.replace('<br/>', '');
            data = data.replace('<br/>', '');
            data = data.replace('@', '<br/>@');
            data = data.replace(/@/g, '<br/>@');


            data = data.replace('@', '<br/>@');
            data = data.replace(/null/g, '');
            data = data.replace("<br><br/><br/>", '');

            data += " <div style='text-align:right;margin-right:10px;margin-bottom:10px'>";
            data += " <button id='CloseBtn' type = 'button'  onclick = 'CloseAll();'><img src='../Img/Btn/Close.png' />关  闭(30秒)</button></div> ";
            $(".Msg").show();
            $(".Msg").html(data);

            $("#next").empty();


            //隐藏table.
            document.getElementById("Table1").style.display = "none";
            document.getElementById("TB_Emps").style.display = "none";
            //document.getElementById("Btn_SelectEmps").style.display = "none";

            var ctrl = document.getElementById("Btn_Send");
            if (ctrl != null)
                ctrl.style.display = "none";

            ctrl = document.getElementById("labInfo");
            if (ctrl != null)
                ctrl.style.display = "none";

            ctrl = document.getElementById("Btn_Close");
            if (ctrl != null)
                ctrl.style.display = "none";

            ctrl = document.getElementById("Btn_SelectEmps");
            if (ctrl != null)
                ctrl.style.display = "none";
        }
        //var num = 30;
        function clock() {

            if ($("#CloseBtn").length == 0)
                return;
            WF_WorkOpt_LeftSecond >= 0 ? WF_WorkOpt_LeftSecond-- : clearInterval(int);
            $("#CloseBtn").html("<img src='../Img/Btn/Close.png' />关  闭(" + WF_WorkOpt_LeftSecond + "秒)");
            if (WF_WorkOpt_LeftSecond == 0)
                CloseAll();
        }

        //取消移交
        function CloseAll() {

            if (isFrameCross == 0) {
                // 取得父页面URL，用于判断是否是来自测试流程
                var pareUrl = window.top.document.referrer;
                if (pareUrl.indexOf("test") != -1 || pareUrl.indexOf("Test") != -1) {
                    // 测试流程时，发送成功刷新测试容器页面右侧
                    window.parent.parent.refreshRight();
                }

                if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                    window.parent.close();
                    if (window.parent.parent != null && window.parent.parent != undefined
                        && pareUrl.indexOf("test") != -1 && pareUrl.indexOf("Test") != -1)
                        window.parent.parent.close();
                    window.parent.returnWorkWindowClose();
                }
            } else {
                window.parent.parent.close();
                ChildrenPostMessage('', 'returnWorkWindowClose');
            }


            window.close();
        }



        //关闭model.
        function CloseModel() {
            if (isFrameCross == 0) {
                if (window.parent != null && window.parent.returnWorkWindowClose != null) {
                    //获取接收人,作用于toNodes.htm页面
                    if (selectEmp != "" && IsSend == "0") {
                        if (pageFrom != null && pageFrom != undefined && pageFrom == "WorkCheckModel") {
                            window.parent.returnWorkWindowClose(selectEmpNo);
                        } else {
                            selectEmp = selectEmp.substring(0, selectEmp.length - 1);
                            window.parent.returnWorkWindowClose(selectEmp);
                        }

                    } else {
                        window.parent.returnWorkWindowClose("");
                    }

                } else {
                    $('body').append($('<div>' + "已取消操作" + '</div>'));
                    window.close();
                }
            } else {
                //获取接收人,作用于toNodes.htm页面
                if (selectEmp != "" && IsSend == "0") {
                    selectEmp = selectEmp.substring(0, selectEmp.length - 1);
                    ChildrenPostMessage(selectEmp, 'returnWorkWindowClose');
                } else {
                    ChildrenPostMessage('', 'returnWorkWindowClose');
                }


            }

        }

        //设置选中的人员
        function selectEmpsWindowClose(data) {

            $('#SelectEmpsModal').modal('hide');
            if (data == '取消') {
                return;
            }

            //返回的人员编号.
            var val = frames["iframeSelectEmpsForm"].window.returnVal.No;

            // alert(val);
            AddEmpsExt(false, val); //调用增加接受人方法，  fase=不让其发送.  val= 选择的人员编号.
            //$('#TB_Emps').val(frames["iframeSelectEmpsForm"].window.returnVal.No);
        }

        //得到行对象
        function getRowObj(obj) {
            var i = 0;
            while (obj.tagName.toLowerCase() != "tr") {
                obj = obj.parentNode;
                if (obj.tagName.toLowerCase() == "table")
                    return null;
            }
            return obj;
        }

        //根据得到的行对象得到所在的行数
        function getRowNo(obj) {
            var trObj = getRowObj(obj);
            var trArr = trObj.parentNode.children;
            for (var trNo = 0; trNo < trArr.length; trNo++) {
                if (trObj == trObj.parentNode.children[trNo]) {
                    alert(trNo + 1);
                }
            }
        }

        //事件
        $(function () {
            //人员选择,输入框拼写补全.
            $("#TB_Emps").bind('input propertychange', function () {

                if ($("#TB_Emps").val() == null || $("#TB_Emps").val() == "") {
                    //alert("输入内容为空！");
                    //return;
                    $("#SelectEmp").hide().html("");
                    return;
                }

                var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt");
                handler.AddPara("FK_Node", GetQueryString("FK_Node"));
                handler.AddPara("WorkID", GetQueryString("WorkID"));
                handler.AddPara("ToNode", GetQueryString("ToNode")); //要到达的节点.
                handler.AddPara("TB_Emps", $("#TB_Emps").val());    //文本框的值
                var data = handler.DoMethodReturnString("AccepterOfGener_SelectEmps");

                if (data.indexOf('err@') == 0) { //如果有错误.
                    alert(data);
                    return;
                }

                data = JSON.parse(data); //返回 No,Name 两个列的值.
                var html = "";
                for (var i = 0; i < data.length; i++) {
                    //$("#SelectEmp").append("<option value='" + data[i].No + "' onclick=selectAdd('" + data[i].No + "')>" + data[i].Name + "</option>");
                    html = html + "<div class='item' onclick='getCon(\"" + data[i].No + "\");' onmouseenter='getFocus(this)'>" + data[i].Name + "</div>";
                }
                $("#SelectEmp").show().html(html);

            });
        });

        //弹窗要调用的接口.
        function selectAdd(No) {
            $("#TB_Emps").val(No);
        }

        //鼠标事件
        function getFocus(obj) {
            $(".item").removeClass("addbg");
            $(obj).addClass("addbg");
        }

        //选择下拉数据
        function getCon(no) {

            //  $("#TB_Emps").val(no);
            $("#SelectEmp").hide().html(""); //关闭掉人员列表。
            AddEmpsExt(false, no); //调用增加人员的方法，fase=不发送.
        }

        function Help() {
            var str = "输入要下一步接受人员可以使用人员名称拼音支持全拼简拼。";
            str += "比如: 查找耿润华您可以输入: grh 或者 gengrh 或者 gengrunhua;"
            str += " 支持单位名称,比如：耿润华/集团信息中心， 可以输入为 grh/jtxxzx";
            layer.alert(str, { icon: 6 });
        }

        //高级选择
        function AdvSelect() {

            var url = "./Selecter/ByStation.htm?WorkID=" + GetQueryString("WorkID") + "&ToNode=" + GetQueryString("ToNode");
            url += "&FK_Node=" + GetQueryString("FK_Node");
            OpenEasyUiDialogExtCloseFunc(url, '设置人员', 780, 380, null);

        }


    </script>

</head>
<body>
    <div class="Msg" style="text-align: left;padding-left:25px; display:none;">
        <img src='../Img/loading.gif' alt="" />页面数据正在加载中，请稍候......
    </div>
    <div class="divFieldly" style="text-align: left;padding-left:25px; display:none;">

    </div>
    <div class="divTech" style="text-align: left;padding-left:25px; display:none;">
    </div>
    <div class="techMsg" style="text-align: left;padding-left:25px; display:none;">
    </div>



    <table class="table table-striped" id="Table1" style="width:98%;padding:5px; margin:10px;">
        <!-- <caption>下一步接受人员列表</caption>-->
        <thead>
            <tr id="title" class="Sum">
                <td style="width:40px; font-weight:bolder">#</td>
                <!--<th>编号 </th>-->
                <td style="width:30%; font-weight:bolder">姓名</td>
                <!--<td style="width:40%; font-weight:bolder">部门  &nbsp; - &nbsp;  <a href="javascript:Ref()">刷新</a></td>-->
                <td style="width:40%; font-weight:bolder">部门</td>

                <td style="width:60px; font-weight:bolder" colspan="3">操作</td>
            </tr>
        </thead>
        <tbody>
        </tbody>
    </table>
    <div style="margin-left:20px">
        <div style="float:left;margin-top:4px">

            <input type="text" id="TB_Emps" name="TB_Emps"
                   title="输入: zs或zhangs或zhangsan"
                   placeholder="查张三,您可输入: zs或zhangs或zhangsan"
                   value='' style="width:350px;" />

            <div id="SelectEmp"></div>
            <div style="float:right;padding-bottom:5px;">
                <button id="Btn_SelectEmps">
                    <img src="../Img/Btn/AddLeader.png" /> 选人
                </button>
            </div>

        </div>
        <div id="next">
            <!--<input type="button" value="增加下一步工作处理人" id="Btn_AddEmps" onclick="AddEmps(false);"/>-->
            <!--<input type="button" id="Btn_SelectAdv" onclick="AdvSelect()" value='选Bate' />-->


            <button onclick="Send();" id="Btn_Send">
                <img src="../Img/Btn/Send.png" /> 发送
            </button>

            <button onclick="CloseModel();" id="Btn_Close">
                <img src="../Img/Btn/Close.png" /> 关闭
            </button>

            <!--<a href="javascript:Help()">帮助?</a>-->
            <!--<div id="HelpInfo">
                <ul>
                    <li>输入要下一步接受人员可以使用人员名称拼音支持全拼简拼. </li>
                    <li>比如:查找耿润华您可以输入: grh 或者 gengrh 或者 gengrunhua </li>
                    <li>支持单位名称比如：耿润华/集团信息中心， 可以输入为 grh/jtxxzx </li>
                </ul>
            </div>-->
        </div>

    </div>

    <br />


</body>
</html>
